home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Very Best of Atari Inside
/
The Very Best of Atari Inside 1.iso
/
mint
/
mntlb20
/
lib
/
memchr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-11
|
717b
|
39 lines
/* from Henry Spencer's stringlib */
#include <stddef.h>
#include <string.h>
/*
* memchr - search for a byte
*
* CHARBITS should be defined only if the compiler lacks "unsigned char".
* It should be a mask, e.g. 0377 for an 8-bit machine.
*/
#ifndef CHARBITS
# define UNSCHAR(c) ((unsigned char)(c))
#else
# define UNSCHAR(c) ((c)&CHARBITS)
#endif
void *
memchr(s, ucharwanted, size)
const void * s;
int ucharwanted;
size_t size;
{
register const char *scan;
register size_t n;
register int uc;
scan = (const char *) s;
uc = UNSCHAR(ucharwanted);
for (n = size; n > 0; n--)
if (UNSCHAR(*scan) == uc)
return((void *)scan);
else
scan++;
return(NULL);
}